<template>
  <section class="app-container">
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters" @submit.native.prevent>
        <el-form-item>
          <el-input v-model="filters.name" placeholder="赛事名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getProject">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>
        <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="projectData" highlight-current-row @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="赛事名称" min-width="120">
      </el-table-column>
      <el-table-column prop="format" label="赛制" width="100" :formatter="formatFormat">
      </el-table-column>
      <el-table-column prop="charge" label="项目负责人" width="120" :formatter="formatCharge">
      </el-table-column>
      <el-table-column prop="major" label="专业" min-width="120">
      </el-table-column>
      <el-table-column prop="projectDate" label="申请立项日期" min-width="160">
      </el-table-column>
      <el-table-column prop="sponsor" label="主办单位" min-width="100">
      </el-table-column>
      <el-table-column
        prop="status"
        label="审核状态"
        :filter-method="filterStatus"
        width="100"
        :filters="[{ text: '通过', value: '3' }, { text: '不通过', value: '2' },{text: '待审核', value : '1'},{text : '待提交', value : '0'}]"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == '0'"
                  :type="scope.row.status === '3' ? 'primary' : 'success'"
                  disable-transitions>待提交</el-tag>
          <el-tag v-if="scope.row.status == '1'"
                  :type="scope.row.status === '3' ? 'primary' : 'success'"
                  disable-transitions >待审核</el-tag>
          <el-tag v-if="scope.row.status == '3'"
                  :type="scope.row.status === '3' ? 'primary' : 'success'"
                  disable-transitions>已通过</el-tag>
          <el-tag v-if="scope.row.status == '2'"
                  :type="scope.row.status === '3' ? 'primary' : 'success'"
                  disable-transitions>不通过</el-tag>
        </template>
      </el-table-column>


      <el-table-column label="操作" width="290">
        <template slot-scope="scope">
          <el-button size="small" v-show="scope.row.status === '0'" type="primary" @click="handleCommit(scope.$index, scope.row)">提交</el-button>
          <el-button size="small" v-show="scope.row.status === '0'" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="success" @click="handleDetail(scope.$index, scope.row)">详情</el-button>
          <el-button type="danger" v-show="scope.row.status === '2' || scope.row.status === '0' " size="small" @click="singleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      @size-change="handleSizeChange"
      :current-page="page"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>

    <!--编辑界面-->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-row>
          <input type="hidden" v-model="editForm.id">
        <el-col :span="14">
        <el-form-item label="赛事名称" prop="name">
          <el-input v-model="editForm.name" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
       <!-- <el-form-item label="项目负责人" prop="charge">
          <el-input v-model="editForm.charge" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>-->
        <el-form-item label="组赛单位" prop="organization">
          <el-input v-model="editForm.organization" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="专业" prop="major">
          <el-input v-model="editForm.major" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="竞赛起始日期" prop="startDate">
          <el-date-picker v-show="dialogStatus != 'detail'"
            v-model="editForm.startDate"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
          <el-input  v-show="dialogStatus == 'detail'" v-model="editForm.startDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="竞赛结束日期" prop="endDate">
          <el-date-picker v-show="dialogStatus != 'detail'"
            v-model="editForm.endDate"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
          <el-input v-show="dialogStatus == 'detail'" v-model="editForm.endDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>

        </el-form-item>
        <el-form-item label="赛制" prop="format">
          <el-radio-group v-model="editForm.format" >
            <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="1">单人赛</el-radio>
            <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="2">团体赛</el-radio>
          </el-radio-group>

        </el-form-item>
        <el-form-item label="申请立项日期" prop="projectDate" >
          <el-date-picker v-show="dialogStatus != 'detail'"
            v-model="editForm.projectDate"
            type="datetime"
            placeholder="选择日期时间">
          </el-date-picker>
          <el-input v-show="dialogStatus == 'detail'" v-model="editForm.projectDate" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>

        </el-form-item>
        <el-form-item label="主办单位" prop="sponsor" >
          <el-input v-model="editForm.sponsor" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="竞赛承办单位" prop="contractor">
          <el-input v-model="editForm.contractor" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
        </el-form-item>
        <el-form-item label="联系电话" prop="phone">
          <el-input v-model="editForm.phone" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
        </el-form-item>
        </el-col>

        <el-col :span="8">
        <el-form-item label="注册费" prop="enroll">
          <el-input-number v-model="editForm.enroll" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
        </el-form-item>
        <el-form-item label="差旅费" prop="travel">
          <el-input-number v-model="editForm.travel" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
        </el-form-item>
        <el-form-item label="培训费" prop="train">
          <el-input-number v-model="editForm.train" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
        </el-form-item>
        <el-form-item label="指导费" prop="guide">
          <el-input-number v-model="editForm.guide" :disabled="dialogStatus == 'detail'"></el-input-number>
        </el-form-item>
        <el-form-item label="耗材费" prop="consume">
          <el-input-number v-model="editForm.consume" :disabled="dialogStatus == 'detail'"></el-input-number>
        </el-form-item>
        <el-form-item label="奖金" prop="bonus">
          <el-input-number v-model="editForm.bonus" :disabled="dialogStatus == 'detail'" ></el-input-number>
        </el-form-item>
        <el-form-item label="其他" prop="other">
          <el-input-number v-model="editForm.other" :disabled="dialogStatus == 'detail'" ></el-input-number>
        </el-form-item>
        <el-form-item label="合计" >
          <el-input-number v-model="editForm.sum" disabled ></el-input-number>
        </el-form-item>

        <el-form-item label="邮件" prop="mail">
          <el-input v-model="editForm.mail" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 180px;"></el-input>
        </el-form-item>
        </el-col>
        </el-row>

        <el-form-item label="论证组赛的目的和意义" prop="objective">
          <el-input type="textarea" v-model="editForm.objective" :disabled="dialogStatus == 'detail'" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审核意见" v-show="editForm.opinion != undefined">
          <el-input type="textarea" v-model="editForm.opinion" disabled auto-complete="off"></el-input>
        </el-form-item>

        <!--        详情信息-->
        <el-form-item v-show="dialogStatus == 'detail'" label="竞赛邀请函或通知附件" prop="objective">
          <el-input v-show="dialogStatus == 'detail'" v-model="fileName" :disabled="dialogStatus == 'detail'" auto-complete="off"></el-input>
          <a :href="'http://47.100.49.86:8888/subject_competition/upload/'+ editForm.invitation" target="_blank" v-show="dialogStatus != 'add' && editForm.invitation != undefined">预览附件</a>
        </el-form-item>

<!--        添加or修改-->
        <el-tooltip class="item" effect="dark" content="将签字盖章后的项目立项申请书扫描为 PDF 文档" placement="top">
          <div v-if="dialogStatus!='detail'" class="file"  style="margin-left: 40px;float: left;">
            <input v-if="dialogStatus!='detail'"  type="file" @change="getFileBase()">上传附件
          </div>
        </el-tooltip>

        <div style="margin-left: 50px;clear: both">
          <a v-show="dialogStatus == 'update'"  :href="'http://47.100.49.86:8888/subject_competition/upload/'+ editForm.invitation" target="_blank">{{fileName}}</a>
          <a v-show="dialogStatus == 'add'" :href="fileUrl" target="_blank">{{fileName}}</a>
        </div>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="dialogFormVisible=false" v-show="dialogStatus != 'detail'">取消</el-button>
        <el-button @click.native="dialogFormVisible=false"  v-show="dialogStatus == 'detail'">关闭</el-button>
        <el-button v-if="dialogStatus=='add'" type="primary" @click="projectSaveOrUpdate">添加</el-button>
        <el-button v-show="dialogStatus=='update'" type="primary" @click="projectSaveOrUpdate">修改</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
  import Vue from 'vue'
  import {dateFormat} from "../../utils/dateFomat";


  export default {
    data() {
      return {
        fileBase64:[],   //存储文件 base64的值将值传给后端处理
        fileBase64Len:0, // 未存储完成文件 base64的长度
        uploadFlag:false, // 上传文件标识
        fileName:'',      // 上传的文件名称
        fileUrl:"",       // 上传后的文件路径
        fileList:[],
        dialogStatus: '',
        textMap: {
          update: '项目立项修改',
          add: '项目立项申请',
          detail:"项目立项详情",
        },
        dialogFormVisible: false,
        filters: {
          name: ''
        },
        total: 0,
        page: 1,  // 当前页
        limit:10,  // 每页数量
        projectData:[],  // 项目立项数据
        teacherList:[],  // 教师列表
        sels: [], // 列表选中列
        // 编辑界面数据
        editForm: {
          id:0,
          projectId:0,
          budgetId:0,
          status:"",
          opinion:"",
          // 项目基本信息
          name:"",
          charge:"",
          // charge:localStorage.getItem("teacherId"),
          major:"",
          format:"",
          projectDate:"",
          sponsor:"",
          contractor:"",
          objective:"",
          invitation:[],
          phone:"",
          mail:"",
          organization:"",
          startDate:"",
          endDate:"",

          // 经费预算
          enroll:0,
          travel:0,
          train:0,
          guide:0,
          bonus:0,
          other:0,
          consume:0,
          sum:0,

        },
        editFormRules: {
          name: [{ required: true, message: '请输入赛事名称', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          major: [{ required: true, message: '请输入专业', trigger: 'blur' }],
          format: [{ required: true, message: '请选择赛制', trigger: 'blur' }],
          mail: [{ required: true, message: '请输入邮件', trigger: 'blur' }],
          phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          sponsor: [{ required: true, message: '请输入主办单位', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          organization: [{ required: true, message: '请输入组赛单位', trigger: 'blur' }],
          startDate: [{ required: true, message: '请输入竞赛起始日期', trigger: 'blur' }],
          endDate: [{ required: true, message: '请输入竞赛结束日期', trigger: 'blur' }],
          contractor: [{ required: true, message: '请输入竞赛承办单位', trigger: 'blur' }],
          objective: [{ required: true, message: '请输入论证组赛的目的和意义', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          invitation: [{ required: true, message: '请上传竞赛邀请函或通知附件', trigger: 'blur' }],

          enroll: [{ required: true, message: '请输入注册费', trigger: 'blur' }],
          travel: [{ required: true, message: '请输入差旅费', trigger: 'blur' }],
          train: [{ required: true, message: '请输入培训费', trigger: 'blur' }],
          guide: [{ required: true, message: '请输入指导费', trigger: 'blur' }],
          consume: [{ required: true, message: '请输入耗材费', trigger: 'blur' }],
          bonus: [{ required: true, message: '请输入奖金', trigger: 'blur' }],
          other: [{ required: true, message: '请输入其他费用', trigger: 'blur' }],
        },


      }
    },
    mounted() {
      this.getTeacherList();
      this.getProject();
    },
    watch:{
      // 监听上传文件标识
      uploadFlag:function(){
        if (this.uploadFlag == true){
          // 开启上传文件
          this.fileUpload();
          // 关闭上传文件
          this.uploadFlag = false;
        }

      },
      // 监听是否上传文件
      fileBase64:function(){
        if (this.fileBase64.length > this.fileBase64Len){
          // 开启上传文件
          this.uploadFlag = true;
        }
      },


      enroll(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      train(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      travel(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },
      guide(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.sum + value;
      },

    },
    computed: {
      enroll(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel
        + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.other;
      },
      train(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.other;
      },
      travel(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.other;
      },
      guide(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.other;
      },
      sum(){
        this.editForm.sum = this.editForm.enroll + this.editForm.train + this.editForm.travel
          + this.editForm.guide + this.editForm.consume + this.editForm.bonus + this.editForm.other;
      },

    },
    methods: {
      // 将当前上传文件转换为base64
      getFileBase(){
        var _this = this;
        _this.fileBase64Len = _this.fileBase64.length;
        var event = event || window.event;
        var file = event.target.files[0];
        _this.fileName = file.name;
        console.log("name" + file.name + ":" + JSON.stringify(file));
        var reader = new FileReader();
        //转base64
        reader.onload = function(e) {
          _this.fileBase64.push(e.target.result);
        }
        reader.readAsDataURL(file);

      },

      // 上传文件
      fileUpload:function(){
        console.log("name" + this.fileName);
        var _this = this;
        console.log("baseFile" + _this.fileBase64[_this.fileBase64.length - 1]);
        $.ajax({
          url:"http://47.100.49.86:8888/subject_competition/json/Upload_uploadFile.action",
          // url:"http://localhost:8080/subject_competition/json/Upload_uploadFile.action",
          dataType: "json",
          // async: false,
          type: "post",
          data:{
            "name":this.fileName,
            "baseString":this.fileBase64[_this.fileBase64.length - 1],
          },
          success:function (data) {
            _this.fileName = data.name;
            _this.editForm.invitation = data.fileName;
            _this.fileUrl = "http://47.100.49.86:8888/subject_competition/upload/" + data.fileName;
            console.log("url=" + _this.fileUrl);
            // _this.fileUrl = "http://localhost:8080/subject_competition/upload/" + data.fileName;
            console.log("file=" + data.file);
            // 关闭上传文件
            _this.uploadFlag = false;
          },
          error:function () {
            // 关闭上传文件
            _this.uploadFlag = false;
            // 关闭图片加载效果
            // _this.pictureLoading = false;
          }
        });
      },

      // 查询项目信息
      getProject: function () {
        var _this = this;
        let teacher = localStorage.getItem("teacherId");
        if (teacher === 'undefined' || teacher === 'null' || teacher === undefined || teacher === null){
          teacher = "";
        }
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_list.action",
          // url: "http://localhost:8080/subject_competition/json/ProjectApply_list.action",
          type: "post",
          dataType: "json",
          data: {
            name: this.filters.name,
            page: this.page,
            limit: this.limit,
            charge: teacher,
          },
          success: function (res) {
            _this.projectData = res.data;
            _this.total = res.count;

          }
        });
      },
      // 查询全部教师
      getTeacherList(){
        const _this = this;
        $.ajax({
          url: "http://47.100.49.86:8888/subject_competition/json/Teacher_findAll.action",
          // url: "http://localhost:8080/subject_competition/json/Teacher_findAll.action",
          type: "post",
          dataType: "json",
          success: function (res) {
            _this.teacherList = res.teacherList;
          }
        });


      },

      // 显示新增界面
      handleAdd: function () {
        this.dialogStatus = 'add'
        this.dialogFormVisible = true;
        this.fileName = ""; // 置空
        this.editForm = {
          format: '1',
        }
      },
      // 显示编辑界面
      handleEdit(index, row) {
        this.dialogStatus = 'update'
        this.dialogFormVisible = true;
        // 获取当前选中的附件信息
        if(row.invitation != undefined) {
          this.fileName = row.invitation.substring(row.invitation.lastIndexOf("_") + 1);
        }else{
          this.fileName = "";
        }
        this.editForm = Object.assign({}, row)
      },
      // 提交项目立项申请
      handleCommit(index, row){
        this.$confirm('确认提交该项目立项吗?', '提示', {
          type: 'warning'
        })
          .then(() => {
            if (row.status === "0") {
              let _this = this;
              $.ajax({
                url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_update.action",
                // url: "http://localhost:8080/subject_competition/json/ProjectApply_update.action",
                data: {
                  id: row.id,
                  projectId: row.projectId,
                  budgetId: row.budgetId,
                  status: "1",
                },
                dataType: "json",
                type: "post",
                success: function (res) {
                  if (res.code === 0) {
                    _this.getProject();
                    Vue.prototype.$message({
                      message: "提交成功",
                      type: 'success'
                    });
                  } else {
                    Vue.prototype.$message({
                      message: "提交失败",
                      type: 'error'
                    });
                  }
                }

              });
            } else if (data.status === "1") {
              Vue.prototype.$message({
                message: "已经提交，不必重复提交",
                type: 'error'
              });
            }
          })  .catch(() => {
              })
      },
      // 显示详情框
      handleDetail(index, row){
        this.dialogStatus = 'detail';
        // 获取当前选中的附件信息
        if(row.invitation != undefined) {
          this.fileName = row.invitation.substring(row.invitation.lastIndexOf("_") + 1);
        }else{
          this.fileName = "";
        }
        this.dialogFormVisible = true;
        this.editForm = Object.assign({}, row);
      },


      // 添加或修改
      projectSaveOrUpdate: function () {
        var flag = true;
        this.$refs.editForm.validate(valid => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {})
              .then(() => {
                const para = Object.assign({}, this.editForm)
                console.log("para:" + para);
                if (para.startDate != this.editForm.startDate || this.dialogStatus == "add") {
                  /*para.startDate = para.startDate == "" ? dateFormat.formatDate(para.startDate, "yyyy-MM-dd hh:mm:ss")
                  : para.startDate;*/
                  para.startDate = dateFormat.formatDate(para.startDate, "yyyy-MM-dd hh:mm:ss");
                }

                if (para.endDate != this.editForm.endDate || this.dialogStatus == "add") {
                 /* para.endDate = para.endDate == "" ? dateFormat.formatDate(para.endDate, "yyyy-MM-dd hh:mm:ss")
                    : para.endDate;*/
                  para.endDate = dateFormat.formatDate(para.endDate, "yyyy-MM-dd hh:mm:ss");
                }
                if (para.projectDate != this.editForm.projectDate || this.dialogStatus == "add") {
                  /*para.projectDate = para.projectDate == "" ? dateFormat.formatDate(para.projectDate, "yyyy-MM-dd hh:mm:ss")
                    : para.projectDate;*/
                  para.projectDate = dateFormat.formatDate(para.projectDate, "yyyy-MM-dd hh:mm:ss");
                }

                var _this = this;

                let charge = localStorage.getItem("teacherId");
                if (charge === 'undefined' || charge === 'null' || charge === undefined || charge === null){
                  charge = "";
                }
                console.log("charge" + charge + "=" + typeof charge); // string

                // 项目基本信息保存or更新
                $.ajax({
                  url: "http://47.100.49.86:8888/subject_competition/json/Project_saveOrUpdate.action",
                  // url: "http://localhost:8080/subject_competition/json/Project_saveOrUpdate.action",
                  type: "post",
                  dataType: "json",
                  async:false,
                  data: {
                    projectId : para.projectId,
                    name : para.name,
                    organization : para.organization,
                    format : para.format,
                    charge : charge,
                    // charge : para.charge,
                    phone : para.phone,
                    mail : para.mail,
                    startDate : para.startDate,
                    endDate : para.endDate,
                    major : para.major,
                    sponsor : para.sponsor,
                    contractor : para.contractor,
                    projectDate : para.projectDate,
                    objective: para.objective,
                    invitation : para.invitation,

                  },
                  success: function (res) {
                    if(res.code === 0){
                      para.projectId = res.projectId;
                    }else{
                      flag = false;
                    }
                  }
                });

                // 经费信息保存or更新
                if(flag) {
                  $.ajax({
                    url: "http://47.100.49.86:8888/subject_competition/json/Budget_saveOrUpdate.action",
                    // url: "http://localhost:8080/subject_competition/json/Budget_saveOrUpdate.action",
                    type: "post",
                    dataType: "json",
                    async: false,
                    data: {
                      budgetId: para.budgetId,
                      enroll: para.enroll,
                      travel: para.travel,
                      train: para.train,
                      guide: para.guide,
                      consume: para.consume,
                      bonus: para.bonus,
                      other: para.other,
                      sum: para.sum
                    },
                    success: function (res) {
                      if (res.code === 0) {
                        para.budgetId = res.budgetId;
                      } else {
                        flag = false;
                      }
                    }
                  });
                }
                console.log("flag===" + flag);
                // 项目信息的保存or更新
                if(flag) {
                  $.ajax({
                    url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_saveOrUpdate.action",
                    // url: "http://localhost:8080/subject_competition/json/ProjectApply_saveOrUpdate.action",
                    type: "post",
                    dataType: "json",
                    async: false,
                    data: {
                      id: para.id,
                      projectId: para.projectId,
                      budgetId: para.budgetId,
                      status: para.status === undefined ? "0" : para.status
                    },
                    success: function (res) {
                      if (res.code === 0) {
                        _this.dialogFormVisible = false;
                        Vue.prototype.$message({
                          message: "操作成功",
                          type: 'success'
                        });
                        _this.getProject();
                      } else {
                        Vue.prototype.$message({
                          message: "操作失败",
                          type: 'error'
                        });
                      }
                    }
                  });
                }else{
                  Vue.prototype.$message({
                    message: "操作失败",
                    type: 'error'
                  });
                }
              }).catch(e => {
                // 打印一下错误
                console.log("保存or更新出错:" + e)
              })
          }
        })

      },
      // 删除
      singleDel(index, row){
        let flag = true;
        var _this = this;
        this.$confirm('确认删除该记录吗?', '提示', {
          type: 'warning'
        })
          .then(() => {
            console.log("row==========" + JSON.stringify(row));
            if(row.status != '3') {
              if (row.id === 0){
                row.id = undefined;
              }
              if (row.projectId === 0){
                row.projectId = undefined;
              }
              if (row.budgetId === 0){
                row.budgetId = undefined;
              }
              if (row.id != undefined) {
                $.ajax({
                  url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_delete.action",
                  // url: "http://localhost:8080/subject_competition/json/ProjectApply_delete.action",
                  type: "post",
                  dataType: "json",
                  async: false, // 关闭异步
                  data: {
                    ids: "[" + JSON.stringify(row) + "]"
                  },
                  success: function (res) {
                    if (res.code != 0) {
                      flag = false;
                    }
                  }
                });
              }

              if (flag != false && row.projectId != undefined) {
                $.ajax({
                  url: "http://47.100.49.86:8888/subject_competition/json/Project_delete.action",
                  // url: "http://localhost:8080/subject_competition/json/Project_delete.action",
                  type: "post",
                  dataType: "json",
                  async: false, // 关闭异步
                  data: {
                    ids: "[" + JSON.stringify(row) + "]"
                  },
                  success: function (res) {
                    if (res.code != 0) {
                      flag = false;
                    }
                  }
                });
              }
              if (flag != false && row.budgetId != undefined) {
                $.ajax({
                  url: "http://47.100.49.86:8888/subject_competition/json/Budget_delete.action",
                  // url: "http://localhost:8080/subject_competition/json/Budget_delete.action",
                  type: "post",
                  dataType: "json",
                  async: false, // 关闭异步
                  data: {
                    ids: "[" + JSON.stringify(row) + "]"
                  },
                  success: function (res) {
                    if (res.code != 0) {
                      flag = false;
                      _this.$message({
                        message: '删除失败',
                        type: 'success'
                      })
                    } else {
                      _this.$message({
                        message: '删除成功',
                        type: 'success'
                      })
                      _this.getProject();
                    }
                  }
                });
              } else {
                this.$message({
                  message: '删除失败',
                  type: 'error'
                })
              }
            }else{
              this.$message({
                message: '删除失败,不能删除已经通过审核的项目立项',
                type: 'error'
              });
            }

          }).catch(() => {

        })
      },


      // 批量删除
      batchRemove: function () {
        let flag = true;
        var _this = this;
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          // 查看选中的是否含有已经通过审核的项目立项
          this.sels.map(item =>{
            if(item.status === "3"){
              flag = false;
            }
            if (item.id === 0){
              item.id = undefined;
            }
            if (item.projectId === 0){
              item.projectId = undefined;
            }
            if (item.budgetId === 0){
              item.budgetId = undefined;
            }
          });
          if (flag != false) {

            if (this.sels.map(item => item.id).toString() != undefined) {
              $.ajax({
                url: "http://47.100.49.86:8888/subject_competition/json/ProjectApply_delete.action",
                // url: "http://localhost:8080/subject_competition/json/ProjectApply_delete.action",
                type: "post",
                dataType: "json",
                async: false, // 关闭异步
                data: {
                  ids: JSON.stringify(this.sels)
                },
                success: function (res) {
                  if (res.code != 0) {
                    flag = false;
                  }
                }
              });
            }

            if (flag != false && this.sels.map(item => item.projectId).toString() != undefined) {
              $.ajax({
                url: "http://47.100.49.86:8888/subject_competition/json/Project_delete.action",
                // url: "http://localhost:8080/subject_competition/json/Project_delete.action",
                type: "post",
                dataType: "json",
                async: false, // 关闭异步
                data: {
                  ids: JSON.stringify(this.sels)
                },
                success: function (res) {
                  if (res.code != 0) {
                    flag = false;
                  }
                }
              });
            }
            if (flag != false && this.sels.map(item => item.budgetId).toString() != undefined) {
              $.ajax({
                url: "http://47.100.49.86:8888/subject_competition/json/Budget_delete.action",
                // url: "http://localhost:8080/subject_competition/json/Budget_delete.action",
                type: "post",
                dataType: "json",
                async: false, // 关闭异步
                data: {
                  ids: JSON.stringify(this.sels)
                },
                success: function (res) {
                  if (res.code != 0) {
                    flag = false;
                    _this.$message({
                      message: '删除失败',
                      type: 'success'
                    })
                  } else {
                    _this.$message({
                      message: '删除成功',
                      type: 'success'
                    })
                    _this.getProject();
                  }
                }
              });
            } else {
              this.$message({
                message: '删除失败',
                type: 'error'
              })
            }
          }else {
            this.$message({
              message: '删除失败,不能删除已经通过审核的项目立项',
              type: 'error'
            })
          }
      }).catch(() => {
        console.log("cancel");
      });

      },
      handleCurrentChange(val) {
        // 获取当前页
        this.page = val;
        // 重新获取数据
        this.getProject();
      },
      handleSizeChange(val){
        this.limit = val;
        this.getProject();
      },

      // 全选单选多选
      selsChange(sels) {
        this.sels = sels
      },

      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      },

      formatFormat: function (row, column) {
        return row.format === "1" ? "单人赛" : "团体赛";
      },
      // 项目负责人编号转换名字显示
      formatCharge:function(row, column){
        this.teacherList.forEach((obj)=>{
          if (obj.teacherId == row.charge){
            row.charge = obj.teacherName;
          }
        });
        return row.charge;
      },
      filterStatus(value, row){
        return row.status === value;
      },
      formatStatus: function (row) {
        if (row.status === "0") {
          return "待提交";
        } else if (row.status === "1") {
          return "待审核";
        } else if (row.status === "2") {
          return "不通过";
        } else if (row.status === "3") {
          return "已批准";
        }
      },


    }

  }
</script>

<style rel="stylesheet/css">
  @keyframes treeTableShow {
    from {opacity: 0;}
    to {opacity: 1;}
  }
  @-webkit-keyframes treeTableShow {
    from {opacity: 0;}
    to {opacity: 1;}
  }
</style>

<style lang="scss" rel="stylesheet/scss" scoped>
  a:link {color:blue;} /* 未访问的链接 */
  a:visited {color:orange;} /* 已访问的链接 */
  a:hover {color:green;} /* 鼠标划过链接 */
  a:active {color:red;} /* 已选中的链接 */


  $color-blue: #2196F3;
  $space-width: 18px;
  .ms-tree-space {
    position: relative;
    top: 1px;
    display: inline-block;
    font-style: normal;
    font-weight: 400;
    line-height: 1;
    width: $space-width;
    height: 14px;
    &::before {
      content: ""
    }
  }
  .processContainer{
    width: 100%;
    height: 100%;
  }
  table td {
    line-height: 26px;
  }

  .tree-ctrl{
    position: relative;
    cursor: pointer;
    color: $color-blue;
    margin-left: -$space-width;
  }



  .file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
  }
  .file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
    cursor: pointer
  }
  .file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
  }
</style>
